//
//  RHNavgationView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/5/31.
//

#import "RHNavgationView.h"
@interface RHNavgationView()

@property (nonatomic, weak) UIViewController *contrller;
@end
@implementation RHNavgationView

-(instancetype)init
{
    if (self = [super initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, kNavHeight)]) {
        [self setupUI];
    }
    return self;
}

-(RHNavgationView*)initWithController:(UIViewController*)controller
{
    if ([self init]) {
        self.controller = controller;
        [self setupUI];
    }
    return self;
}

-(void)setTitle:(NSString *)title
{
    self.titleLab.text = title;
}

-(void)setButtonTitleColor:(UIColor*)color
{
    self.titleLab.textColor = color;
    [self.backBtn setImage:[[UIImage imageNamed:@"back_icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    self.backBtn.tintColor = color;
}
-(void)setupUI
{
    kWeakSelf;
    _titleLab = [QMUILabel labelWithText:@"" font:kBOLDSYSTEMFONT(18) textColor:kCOLOR_HEX(@"#3F4443")];
    [self addSubview:_titleLab];
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kSafe_top+10);
        make.centerX.mas_offset(0);
        make.height.offset(20);
    }];
    
    QMUIButton *backBtn = [[QMUIButton alloc]init];
    [backBtn setImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateNormal];
    [self addSubview:backBtn];
    self.backBtn = backBtn;
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(40);
        make.centerY.equalTo(weakSelf.titleLab);
        make.left.mas_offset(5);
    }];
    [[backBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.controller) {
            [weakSelf.controller.navigationController popViewControllerAnimated:YES];
        }
    }];
}
@end
